// 云函数入口文件
const cloud = require('wx-server-sdk')
const axios = require('axios');
cloud.init()

exports.main = async (event, context) => {
    const { address } = event;
    const ak = 'xoSxtsisj1ZZGepT5xk5evIsdEUSxy36'; 
    const url = `https://api.map.baidu.com/geocoding/v3/?address=${encodeURIComponent(address)}&ak=${ak}&output=json`;

    try {
        const res = await axios.get(url);
        return res.data;
    } catch (error) {
        console.error('地理编码失败', error);
        throw new Error('地点解析失败');
    }
};